<?php

namespace app\admin\controller\auth;

use app\admin\controller\Base;
use app\common\model\auth\AuthAdminConfigModel;

class AuthAdminConfig extends Base
{
    private $example = [
        AuthAdminConfigModel::TYPE_ADMIN_SITE_THEME => [
            'interface' => [//主题配置
                'other' => [//其它配置
                    'closeOnClickModal' => true,//系统后台各个弹出层（即模态框）是否通过点击mobile关闭（即点击阴影层关闭模态框）
                    'clickMenuIsOpenSideMenu' => true,//点击菜单是否打开侧栏菜单
                ],
                'color' => [//颜色配置
                    'mainMenuBagColor' => '#282C34',//主菜单背景颜色
                    'mainHoverMenuBagColor' => '#1890FF',//主菜单hover颜色
                ]
            ]
        ]
    ];

    /**
     * 获取角色站点配置
     */
    public function getConfig()
    {
        $params = request()->only(['type']);
        $this->validate($params, [
            'type' => 'require'
        ], [
            'type.require' => '请选择获取配置类型'
        ]);

        $authAdminConfigModel = new AuthAdminConfigModel;
        $info = $authAdminConfigModel->getConfigInfo($params['type'], $this->adminInfo['id']);
        if (!$info) {
            return response_error($authAdminConfigModel->getError());
        }

        return response_success('', $info);
    }

    /**
     * 获取配置示例
     */
    public function getExample()
    {
        $params = request()->only(['type']);
        $this->validate($params, [
            'type' => 'require'
        ], [
            'type.require' => '请选择获取配置类型'
        ]);

        dump(json_encode($this->example[$params['type']] ?? [], JSON_UNESCAPED_UNICODE));
        die;
        return response_success('', $this->example[$params['type']] ?? []);
    }

    /**
     * 编辑-配置内容项
     */
    public function editByContent()
    {
        $params = request()->only(['type', 'content']);
        $this->validate($params, [
            'type' => 'require',
            'content|配置内容' => 'require'
        ], [
            'type.require' => '请选择获取配置类型'
        ]);

        $authAdminConfigModel = new AuthAdminConfigModel;
        $info = $authAdminConfigModel->editByContent($params, $this->adminInfo);
        if (!$info) {
            return response_error($authAdminConfigModel->getError());
        }

        return response_success('', $info);
    }

    /**
     * 重置配置
     */
    public function resetting()
    {
        $params = request()->only(['type']);
        $this->validate($params, [
            'type' => 'require',
        ], [
            'type.require' => '请选择获取配置类型'
        ]);

        $authAdminConfigModel = new AuthAdminConfigModel;
        $info = $authAdminConfigModel->resetting($params, $this->adminInfo);
        if (!$info) {
            return response_error($authAdminConfigModel->getError());
        }

        return response_success('', $info);
    }

}